
package com.caration.shell.preference;

import android.R;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

/**
 * A preference only show logo
 * @author Lonn
 *
 */
public class LogoPreference extends Preference {
    private Drawable mLogo;

    public LogoPreference(Context context) {
        this(context, null);
    }

    public LogoPreference(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LogoPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected View onCreateView(ViewGroup parent) {
        final Context context = getContext();
        RelativeLayout root = new RelativeLayout(context);
        ImageView logo = new ImageView(context);
        logo.setId(R.id.icon);
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.CENTER_IN_PARENT);
        params.setMargins(0, 20, 0, 20);
        root.addView(logo, params);
        return root;
    }

    @Override
    protected void onBindView(View view) {
        ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(mLogo);
        super.onBindView(view);
    }

    public void setLogo(Drawable drawable) {
        mLogo = drawable;
    }
}
